package day02;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class ThreadTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        //创建数组接收线程执行返回就诶过
        List<Future<Integer>> futureList = new ArrayList<>();

        for (int i =0;i<=2;i++){
            Future<Integer> submit = executorService.submit(new PrintTask());
            futureList.add(submit);
        }


        for (Future<Integer> future:futureList){
            //这里可能会堵塞线程（如果上面有线程没完成）
            System.out.println(future.get());
        }
        //关闭线程池
        executorService.shutdown();



    }
}
